package com.meixiang.adapter.home;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.meixiang.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * @author yinsujun  Created at 2016/5/5 17:39
 */
public class RepaymentDetailAdapter extends RecyclerView.Adapter<RepaymentDetailAdapter.ViewHolder> {
    private int type;//1账单详情--2已还款
    public RepaymentDetailAdapter(Context context,int type) {
        this.context = context;
        this.type=type;
    }
    private Context context;

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.activity_repayment_detail_list_item, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        if(onItemClickListener!=null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    onItemClickListener.onItemClick(holder.itemView, pos);
                }
            });
        }

        if(type==1){
            holder.tvType.setText("冬日补水超值礼盒套装");
            holder.tvTime.setText("05-06期");
            holder.tvMoney.setText("0.00");
            holder.ivArrow.setVisibility(View.VISIBLE);
        }else if(type==2){
            holder.tvType.setText("自动扣除");
            holder.tvTime.setText("05-05 18:00");
            holder.tvMoney.setText("0.00");
            holder.ivArrow.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        return 3;
    }
    private OnItemClickListener onItemClickListener;
    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.onItemClickListener=onItemClickListener;
    }
    public interface OnItemClickListener{
        void onItemClick(View view,int position);
    }
    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.repayment_detail_tv_type)
        TextView tvType;
        @Bind(R.id.repayment_detail_tv_time)
        TextView tvTime;
        @Bind(R.id.repayment_detail_tv_money)
        TextView tvMoney;
        @Bind(R.id.repayment_detail_iv)
        ImageView ivArrow;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
